package com.beijiteshop.shop.ui.order.adapter

import android.view.LayoutInflater
import com.beijiteshop.libcommon.ext.databinding.inflateBinding
import com.beijiteshop.shop.R
import com.beijiteshop.shop.databinding.IncludeOrderDetailGoodsBinding
import com.beijiteshop.shop.databinding.IncludeOrderGoodsBinding
import com.beijiteshop.shop.databinding.ItemOrderDetailBinding
import com.beijiteshop.shop.databinding.ItemOrderDetailInfoBinding
import com.beijiteshop.shop.model.api.response.GroupGood
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder

/**
 * @Author LiaoZhongKai
 * @Date 2021/3/12 11:21
 * @Description 订单详情页面adapter
 */
class OrderDetailInfoAdapter(data: MutableList<GroupGood>) : BaseQuickAdapter<GroupGood,BaseDataBindingHolder<ItemOrderDetailInfoBinding>>(
    R.layout.item_order_detail_info,data) {

    override fun convert(
        holder: BaseDataBindingHolder<ItemOrderDetailInfoBinding>,
        item: GroupGood
    ) {
        holder.dataBinding?.let {
            it.groupGood = item
            if (!item.goods.isNullOrEmpty()){
                it.orderDetailGoodsContainerLl.removeAllViews()
                //设置物流默认值
                if (item.sendTime.isNullOrEmpty()){
                    item.sendTime = context.resources.getString(R.string.not_delivered)
                }
                if (item.signTime.isNullOrEmpty()){
                    item.signTime = context.resources.getString(R.string.not_signed)
                }
                if (item.trackingNumber.isNullOrEmpty()){
                    item.trackingNumber = context.resources.getString(R.string.not_delivered)
                }
                if (item.dhl.isNullOrEmpty()){
                    item.dhl = context.resources.getString(R.string.not_delivered)
                }
                item.goods!!.forEach { good ->
                    val itemInfoBinding = inflateBinding<IncludeOrderDetailGoodsBinding>(LayoutInflater.from(context))
                    itemInfoBinding.goods = good
                    it.orderDetailGoodsContainerLl.addView(itemInfoBinding.root)
                }
            }
        }
    }

}